var oldObjArrayCheckout = new Array();
var oldObjArrayCheckoutSetPage = new Array();
var setRowObjArrayCheckout = new Array();
var textRoomCheckOut ="";
var textRoomCheckOutSetpage ="";
var textRoomCheckOutPrint ="";
var pager = "";
var getPage = "";
var check = 0;
////////////// Start CheckOut Page ////////////////
function searchAll_checkoutPage(value,e){
	/*if (e.keyCode == 13 && !e.ctrlKey) {
		getReservationRoomManageMent("textSearch",value)
		$("#SearchAll_checkoutPage").val("");
	}*/
}
function getReservationRoomManageMent(data,valueSearch){
	var tab = getCurrentTabData();
	clearData();
	waitingDialog({});
	var dataOld =  $("#typeCheckReservationCheckout").val();
	var searchName = $("#SearchAll_checkoutPage").val();
	if($("#RowpagerCheckOutListRoomManageMent").val() == null){
		tab.lineCheckout = 10;
	}else{
		tab.lineCheckout = $("#RowpagerCheckOutListRoomManageMent").val();
	}
	if($("#pagerCheckOutListRoomManageMent").val() == null){
		var pagePointer = 1; 
	}else{
		var pagePointer = $("#pagerCheckOutListRoomManageMent").val(); 
	}
	var offfset = (tab.lineCheckout*pagePointer)-tab.lineCheckout;
	if($("#RowpagerCheckOutListRoomManageMent").val() == null){
		tab.lineCheckout = 10;
	}else{
		tab.lineCheckout = $("#RowpagerCheckOutListRoomManageMent").val();
	}
	if($("#pagerCheckOutListRoomManageMent").val() == null){
		var pagePointer = 1; 
	}else{
		if(valueSearch!=""&&valueSearch!=undefined){
			var pagePointer = valueSearch; 
		}else{
			var pagePointer = 1;
			tab.pagerNumber = 1;
		}
		//var pagePointer = $("#pagerCheckOutListRoomManageMent").val(); 
	}
	var offfset = (tab.lineCheckout*pagePointer)-tab.lineCheckout;
	var valueDateCheckin = $("#calendar_btw_checkinCheckout").attr("dateofbtwcheckinCheckout");
	var valueDateCheckout = $("#calendar_btw_checkoutCheckout").attr("dateofbtwcheckoutCheckout");
	if(valueDateCheckin!=""&&valueDateCheckout!=""){
		var dateCheckin = $("#calendar_btw_checkinCheckout").attr("dateofbtwcheckinCheckout");
		var dateCheckout = $("#calendar_btw_checkoutCheckout").attr("dateofbtwcheckoutCheckout");
		$("#calendar_btw_checkinCheckout").val($.datepicker.parseDate("yy-mm-dd",dateCheckin).getFormatedString());
		$("#calendar_btw_checkoutCheckout").val($.datepicker.parseDate("yy-mm-dd",dateCheckout).getFormatedString());
		$('#calendar_btw_checkinCheckout').attr('dateofbtwcheckinCheckout',dateCheckin);
		$('#calendar_btw_checkoutCheckout').attr('dateofbtwcheckoutCheckout',dateCheckout);
		tab.valueDateCheckin = dateCheckin;
		tab.valueDateCheckout = dateCheckout;
	}else{
		var dateCheckin = new Date().addDate(0).toSystemFormat();
		var dateCheckout= new Date().addDate(0).toSystemFormat();
		$("#calendar_btw_checkinCheckout").val($.datepicker.parseDate("yy-mm-dd",dateCheckin).getFormatedString());
		$("#calendar_btw_checkoutCheckout").val($.datepicker.parseDate("yy-mm-dd",dateCheckout).getFormatedString());
		$('#calendar_btw_checkinCheckout').attr('dateofbtwcheckinCheckout',dateCheckin);
		$('#calendar_btw_checkoutCheckout').attr('dateofbtwcheckoutCheckout',dateCheckout);
		tab.valueDateCheckin = dateCheckin;
		tab.valueDateCheckout = dateCheckout;
	}
	if(data=="CheckOutListRoomManageMent"){
		if(pagePointer>1){
			var link = "/reservationService?func=getReservationAllCheckoutOnly&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+(pagePointer-1)+"&SearchAll_checkoutPage="+searchName;
			var linkSet = "/reservationService?func=getReservationAllCheckoutOnly&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&SearchAll_checkoutPage="+searchName;
			tab.linkSet = linkSet;
			simpleservice(link,null,showDataResRoomManageMentSetCountCheckout,tab.lineCheckout);
		}else{
			tab.beforePageCheckout = ""; 
			tab.beforeSubPageCheckout = "";
			var link = "/reservationService?func=getReservationAllCheckoutOnly&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&SearchAll_checkoutPage="+searchName;
			simpleservice(link,null,showDataResRoomManageMent,data);
		}
	}else if(data=="G"){
		tab.typeReservationCheckout = data;
		typeReservationCheckoutFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,searchName);
		//showDataResRoomManageMent(data,"G");
	}else if(data=="S"){
		tab.typeReservationCheckout = data;
		typeReservationCheckoutFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,searchName);
		//showDataResRoomManageMent(data,"S");
	}else if(data=="A"){
		tab.typeReservationCheckout = data;
		typeReservationCheckoutFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,searchName);
		//showDataResRoomManageMent(data,"A");
	}/*else if(data == "textSearch"){
		showDataResRoomManageMent(data,"textSearch");
	}*/else if(data == "dateSearch"){
		tab.beforePageCheckout = ""; 
		tab.beforeSubPageCheckout = "";
		var dataOld =  $("#typeCheckReservationCheckout").val();
		var valueDateCheckin = $("#calendar_btw_checkinCheckout").attr("dateofbtwcheckinCheckout");
		var valueDateCheckout = $("#calendar_btw_checkoutCheckout").attr("dateofbtwcheckoutCheckout");
		tab.checkinCheckout = valueDateCheckin;
		tab.checkoutCheckout = valueDateCheckout;
		if(valueDateCheckin!=""&&valueDateCheckout!=""){
			var dateCheckin = valueDateCheckin;
			tab.valueDateCheckin = valueDateCheckin;
			var dateCheckout= valueDateCheckout;
			if(dataOld=="G"){
				tab.typeReservationCheckout = dataOld;
				if(pagePointer>1){
					var link = "/reservationService?func=getReservationAllCheckoutOnlyGroup&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					var linkSet = "/reservationService?func=getReservationAllCheckoutOnlyGroup&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					tab.linkSet = linkSet;
					simpleservice(link,null,showDataResRoomManageMentSetCountCheckout,tab.lineCheckout);
				}else{
					var link = "/reservationService?func=getReservationAllCheckoutOnlyGroup&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					simpleservice(link,null,showDataResRoomManageMent,data);
				}
			}else if(dataOld=="S"){
				tab.typeReservationCheckout = dataOld;
				if(pagePointer>1){
					var link = "/reservationService?func=getReservationAllCheckoutOnlySingle&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					var linkSet = "/reservationService?func=getReservationAllCheckoutOnlySingle&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					tab.linkSet = linkSet;
					simpleservice(link,null,showDataResRoomManageMentSetCountCheckout,tab.lineCheckout);
				}else{
					var link = "/reservationService?func=getReservationAllCheckoutOnlySingle&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					simpleservice(link,null,showDataResRoomManageMent,data);
				}
			}else if(dataOld=="A"){
				tab.typeReservationCheckout = dataOld;
				if(pagePointer>1){
					var link = "/reservationService?func=getReservationAllCheckoutOnly&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					var linkSet = "/reservationService?func=getReservationAllCheckoutOnly&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					tab.linkSet = linkSet;
					simpleservice(link,null,showDataResRoomManageMentSetCountCheckout,tab.lineCheckout);
				}else{
					tab.beforePageCheckout = ""; 
					tab.beforeSubPageCheckout = "";
					var link = "/reservationService?func=getReservationAllCheckoutOnly&offset="
						+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
						+"&SearchAll_checkoutPage="+searchName;
					simpleservice(link,null,showDataResRoomManageMent,data);
				}
			}
		}else{
			$("#calendar_btw_checkinCheckout").select();
		}
	}
}
function showDataResRoomManageMent(data,output){
	var tab = getCurrentTabData();
	var valueDateCheckin = tab.valueDateCheckin;
	var valueDateCheckout = tab.valueDateCheckout;
	if(valueDateCheckin!=""&&valueDateCheckout!=""){
		var dateCheckin = valueDateCheckin;
	  	var dateCheckout = valueDateCheckout;
	  	$("#calendar_btw_checkinCheckout").val($.datepicker.parseDate("yy-mm-dd",dateCheckin).getFormatedString());
		$("#calendar_btw_checkoutCheckout").val($.datepicker.parseDate("yy-mm-dd",dateCheckout).getFormatedString());
		$('#calendar_btw_checkinCheckout').attr('dateofbtwcheckinCheckout',dateCheckin);
		$('#calendar_btw_checkoutCheckout').attr('dateofbtwcheckoutCheckout',dateCheckout);
	}
	// set for pager
	tab.tablePager = "tablepagingCheckout";
	tab.pagerNumberField = "pagerCheckOutListRoomManageMent";
	tab.functionGetData = "getReservationRoomManageMent";
	tab.pageName = "CheckOutListRoomManageMent";
	tab.pageNavPosition = "pageNavPositionCheckout";
	tab.trCheck = "trcheckout";
	
	if(tab.checkinCheckout!=undefined){
		$('#calendar_btw_checkinCheckout').val($.datepicker.parseDate("yy-mm-dd",tab.checkinCheckout).getFormatedString());
		$('#calendar_btw_checkinCheckout').attr('dateofBtwCheckinCheckout',tab.checkinCheckout);
	}
	if(tab.checkoutCheckout!=undefined){
		$('#calendar_btw_checkoutCheckout').val($.datepicker.parseDate("yy-mm-dd",tab.checkoutCheckout).getFormatedString());
		$('#calendar_btw_checkoutCheckout').attr('dateofBtwCheckoutCheckout',tab.checkoutCheckout);
	}
	if(tab.typeReservationCheckout!=undefined){
		$('#typeCheckReservationCheckout option[value='+tab.typeReservationCheckout+']').attr('selected', 'selected');
	}
	if(data.trim()=="[]"){
		$("[clearTr=checkoutReservation]").remove();
		var textDataEmpty = '<tr clearTr="checkoutReservation" >'+
		'<td colspan="100%" style="text-align:center;" >'+
		dataEmpty+
		'</td>'+
		'</tr>';
		textRoomCheckOut = textDataEmpty;
		$("#CheckOutListRoomManageMent_Id_Tr").replaceWith("<tr id=CheckOutListRoomManageMent_Id_Tr ></tr>"+textRoomCheckOut);
		textRoomCheckOut = '';
	}else{
		$("[clearTr=checkoutReservation]").remove();
		var objArray = new Array();
		if((data=="textSearch"||data=="G"||data=="S"||data=="A")&&data!="dateSearch"){
			objArray = oldObjArrayCheckout;
			objArray = objArray[0];
		}else{
			objArray = JSON.parse(data);
			oldObjArrayCheckout = objArray;
			objArray = objArray[0];
		}
		setRowObjArrayCheckout = objArray;
		sortIdRoommanagement(objArray); // sort for show display
		textRoomCheckOutPrint = '';
		var checkBgColor = 0;
		var countGroup = 0;
		var OldGroupId =0;
		var emailPic = '<img src=../images/components/roommanagement/email.png alt=Note height=15 width=20>';
		var printPci = '<img src=../images/components/roommanagement/print.png alt=Note height=15 width=20>';
		var valueSearch = $("#SearchAll_checkoutPage").val();
		var firstSelect = "";
		var typeReservation = $("#typeCheckReservationCheckout").val();
		var numberSet = tab.beforePageCheckout; 
		var numberSubSet = tab.beforeSubPageCheckout;
		var number = "";
		for(var i =0;i<objArray.length;i++){
			var nameReservation = "";
			if(objArray[i].name!=""&&objArray[i].name!=undefined){
				nameReservation = objArray[i].name.split(" ");
			}
			if(objArray[i].description!=undefined&&objArray[i].description!=""){
				Description = objArray[i].description;
			}else{
				Description = "";
			}
			var Objtitle = objArray[i].reservationTitle;
			
			if(objArray[i].groupId!=0){
				var ObjgroupId = "G"+objArray[i].groupId;
			}else{
				var ObjgroupId = 0;
			}
			var ObjId = objArray[i].id;
			/*var checkContinue = checkedFilter(output,valueSearch,nameReservation,firstSelect,Objtitle,ObjgroupId,typeReservation,ObjId);
			if(checkContinue==1){
				continue;
			}*/
			var textSubRes = "";
			var textSubResPrint = "";
			if(objArray[i].groupId!="0"){
				if(objArray[i].subList!=undefined){
					var setDateFormat = new Date(objArray[i].date);
					var setYear = setDateFormat.getFullYear();
					var setMonth = setDateFormat.getMonth()+1;
					var setDay = setDateFormat.getDate();
					var DateFormatThai = setYear+'-'+setMonth+'-'+setDay;
					var setFateFormatCheckout = setDateFormat.addDate(parseInt(objArray[i].span));
					var setYearCheckOut = setFateFormatCheckout.getFullYear();
					var setMonthCheckOut = setFateFormatCheckout.getMonth()+1;
					var setDayCheckOut = setFateFormatCheckout.getDate();
					var DateformatThaiCheckout = setYearCheckOut+'-'+setMonthCheckOut+'-'+setDayCheckOut;
					groupId = objArray[i].groupIdString;
					var splitResIdInGroup = objArray[i].resList.split(",");
					var checkBgColorG =0;
					var StatusResInGroup = "";
					var statusRecord = "";
					for(var subRes = 0;subRes<objArray[i].subList.length;subRes++){
						var setDateFormatRes = new Date(objArray[i].subList[subRes].date);
						var setFateFormatCheckoutRes = new Date(objArray[i].subList[subRes].dateTo);
						var ShowNameGuest = "";
						var DescriptionSubRes = "";
						if(objArray[i].subList[subRes].description!=undefined&&objArray[i].subList[subRes].description!=""){
							DescriptionSubRes = objArray[i].subList[subRes].description;
						}else{
							DescriptionSubRes = "";
						}
						/// Name Empty
						if(objArray[i].subList[subRes].name!=undefined){
							ShowNameGuest = objArray[i].subList[subRes].name
						}
						///
						if(objArray[i].subList[subRes].reservationTitle=="Reserved Rooms"){
							StatusResInGroup = statusResv;
						}else if(objArray[i].subList[subRes].reservationTitle=="Checked-out Rooms"){
							StatusResInGroup = statusCheckOut;
						}else if(objArray[i].subList[subRes].reservationTitle=="Temp Rooms"){
							StatusResInGroup = statusTempResv;
						}else if(objArray[i].subList[subRes].reservationTitle=="Cancel Reservation"){
							StatusResInGroup = statusCancelCheckin;
						}else{
							StatusResInGroup = statusCheckin;
						}
						if(checkBgColorG==0){
							statusRecord = 'dataRecordBot';
							checkBgColorG = 1;
						}else{
							statusRecord = 'dataRecordBot';
							checkBgColorG =0;
						}
						var showDisplayGuestname = "";
						if(ShowNameGuest==""){
							showDisplayGuestname = '<tr clearTr=checkoutReservation class="'+statusRecord+'" onclick="if(linkClick==true)noGuestName();" id="btnEditS" >';
						}else{
							showDisplayGuestname = '<tr clearTr=checkoutReservation class="'+statusRecord+'" onclick="if(linkClick) CallEditReservedPageWithLoadElement(id,'+objArray[i].subList[subRes].id+')"  id="btnEditS" >';
						}
						var obj = objArray[i].subList[subRes];
						//object to string
						objToStr(obj);
						objArray[i].subList[subRes] = obj;
						var re2 = /"/gi;
						// run number
						var runnumberSub = "";
						
						if(getCurrentTabData().beforePageCheckout!=undefined&&getCurrentTabData().beforePageCheckout!=""){
							runnumberSub = (numberSet+1)+"."+(subRes+1);
						}else{
							runnumberSub = (i+1)+"."+(subRes+1);
						}
						var sendData = JSON.stringify(objArray[i].subList[subRes]).replace(re2, "'");
							textSubRes += showDisplayGuestname+
							'<td colspan="2" class="spanDataCenter">'+
							runnumberSub+
							'</td>'+
							'<td class="spanDataCenter">' +
								'<span>'+objArray[i].subList[subRes].id+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span class="guestName" >'+ShowNameGuest+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span>'+setDateFormatRes.getFormatedString()+'-'+setFateFormatCheckoutRes.getFormatedString()+' ('+objArray[i].subList[subRes].span+')</span>'+
							'</td>'+
							'<td class="spanDataCenter"> '+
								'<span>'+objArray[i].subList[subRes].roomTypeName+'('+objArray[i].subList[subRes].roomName+')'+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">' +
								'<span>'+adult+'('+objArray[i].subList[subRes].adult+') - '+child+'('+objArray[i].subList[subRes].child+')'+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								StatusResInGroup+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span>'+toCurrencyString(currencyStringToNumber(objArray[i].subList[subRes].defaultCherge))+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span><div class="fongwordwarp" >'+DescriptionSubRes+'</div></span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<div onmouseover="linkClick=false;" onmouseout="linkClick=true;" >'+
								'<span  onclick="printRoomManagementCheckout('+sendData+')" >'+printPci+'</span>'+
							'<span id="sendMail'+objArray[i].subList[subRes].id+'" onclick="sendMail(id)"> '+emailPic+'</span></div>'+
							'</td>'+
							'</tr>';
							textSubResPrint += '<tr clearTr=checkoutReservation class="'+statusRecord+'" onclick="if(linkClick&&ShowNameGuest!="") CallEditReservedPageWithLoadElement(id,'+objArray[i].subList[subRes].id+')"  id="btnEditS" >'+
							'<td colspan="2" class="spanDataCenter">'+
							runnumberSub+
							'</td>'+
							'<td class="spanDataCenter">' +
								'<span>'+objArray[i].subList[subRes].id+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span class="guestName" >'+ShowNameGuest+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span>'+setDateFormatRes.getFormatedString()+'-'+setFateFormatCheckoutRes.getFormatedString()+' ('+objArray[i].subList[subRes].span+')</span>'+
							'</td>'+
							'<td class="spanDataCenter"> '+
								'<span>'+objArray[i].subList[subRes].roomTypeName+'('+objArray[i].subList[subRes].roomName+')'+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">' +
								'<span>'+adult+'('+objArray[i].subList[subRes].adult+') - '+child+'('+objArray[i].subList[subRes].child+')'+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								StatusResInGroup+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span>'+toCurrencyString(currencyStringToNumber(objArray[i].subList[subRes].defaultCherge))+'</span>'+
							'</td>'+
							'<td class="spanDataCenter">'+
								'<span><div class="fongwordwarp" >'+DescriptionSubRes+'</div></span>'+
							'</td>'+
							'</tr>';
					}
					///Check StatusGroup
					var obj = objArray[i].subList;
					showStatusResInGroup = checkStatusReservationGroup(obj);
						var dateFormatDisplay = setDateFormat.getFormatedString();
						var obj = objArray[i];
						var  checksub = 0;
						for (var k in obj)
						{
						    if(obj.subList!=undefined && checksub == 0){
						    	checksub = 1;
						    	var newsubListObjString = new Array();
						    	for(var sublistGroup=0;sublistGroup<obj.subList.length;sublistGroup++){
						    		var objsub = obj.subList[sublistGroup];
						    		for (var j in objsub)
									{
							    		if (objsub.hasOwnProperty(j))
									    {
							    			if(j=="OtherChargeList"||j=="payment"||j=="ChargeList"){
							    	    		var objC =  objsub[j];
							    	    		var objPut = new Array();
							    	    		for(var c = 0;c<objC.length;c++){
							    	    			for(var j in objC[c]){
							    		    			if(objC[c].hasOwnProperty(j)){
							    		    				objC[c][j] = String(objC[c][j]);
							    		    			}
							    		    		}
							    	    			objPut.push(objC[c]);
							    	    		}
							    	    		objsub[j] = objPut;
							    	    	}else{
							    	    		objsub[j] = String(objsub[j]);
							    	    	}
									    }
									}
						    		newsubListObjString.push(objsub);
						    	}
						    	obj.subList = newsubListObjString;
						    }
							if (obj.hasOwnProperty(k))
						    {
						        if(k=="subList")
						        	continue;
								obj[k] = String(obj[k]);
						    }
						}
						objArray[i] = obj;
						var re2 = /"/gi;
						var sendDataGroup = JSON.stringify(objArray[i]).replace(re2, "'");
						if(tab.beforePageCheckout!=undefined&&tab.beforePageCheckout!=""){
							numberSet = numberSet+1;
							number = numberSet;
						}else{
							number = (i+1);
						}
						textRoomCheckOut += '<tr clearTr=checkoutReservation class="dataRecordGroup" onclick="if(linkClick) CallEditReservedPageWithLoadElement(id,'+objArray[i].groupIdString+')"  id="btnEditG" >'+
						'<td class="spanDataCenter">'+
							number+'(<span id=groupCount'+objArray[i].groupIdString+' >'+objArray[i].resList.split(",").length+'</span>)'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>G'+objArray[i].groupIdString+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span class="ownerName" >'+objArray[i].name+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+dateFormatDisplay+'-'+setFateFormatCheckout.getFormatedString()+' ('+objArray[i].span+')</span>'+
						'</td>'+
						'<td class="spanDataCenter"> '+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
						'<span>'+showStatusResInGroup+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span><div class="fongwordwarp" >'+Description+'</div></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<div onmouseover="linkClick=false;" onmouseout="linkClick=true;" >'+
							'<span  onclick="printRoomManagementCheckout('+sendDataGroup+')" >'+printPci+'</span>'+
						'<span id="sendMail'+objArray[i].groupIdString+'" onclick="sendMail(id)"> '+emailPic+'</span></div>'+
						'</td>'+
					'</tr>'+textSubRes;
						textRoomCheckOutPrint += '<tr clearTr=checkoutReservation class="dataRecordGroup" onclick="if(linkClick) CallEditReservedPageWithLoadElement(id,'+objArray[i].groupIdString+')"  id="btnEditG" >'+
						'<td class="spanDataCenter">'+
							number+'(<span id=groupCount'+objArray[i].groupIdString+' >'+objArray[i].resList.split(",").length+'</span>)'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>G'+objArray[i].groupIdString+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span class="ownerName" >'+objArray[i].name+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+dateFormatDisplay+'-'+setFateFormatCheckout.getFormatedString()+' ('+objArray[i].span+')</span>'+
						'</td>'+
						'<td class="spanDataCenter"> '+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
						'<span>'+showStatusResInGroup+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span><div class="fongwordwarp" >'+Description+'</div></span>'+
						'</td>'+
					'</tr>'+textSubResPrint;
						checkBgColor =1;
				}else{
					var setDateFormatRes = new Date(objArray[i].date);
					var setFateFormatCheckoutRes = new Date(objArray[i].dateTo);
					var ShowNameGuest = "";
					var DescriptionSubRes = "";
					if(objArray[i].description!=undefined&&objArray[i].description!=""){
						DescriptionSubRes = objArray[i].description;
					}else{
						DescriptionSubRes = "";
					}
					/// Name Empty
					if(objArray[i].name!=undefined){
						ShowNameGuest = objArray[i].name;
					}
					///
					if(objArray[i].reservationTitle=="Reserved Rooms"){
						StatusResInGroup = statusResv;
					}else if(objArray[i].reservationTitle=="Checked-out Rooms"){
						StatusResInGroup = statusCheckOut;
					}else if(objArray[i].reservationTitle=="Temp Rooms"){
						StatusResInGroup = statusTempResv;
					}else if(objArray[i].reservationTitle=="Cancel Reservation"){
						StatusResInGroup = statusCancelCheckin;
					}else{
						StatusResInGroup = statusCheckin;
					}
					if(checkBgColorG==0){
						statusRecord = 'dataRecord';
						checkBgColorG = 1;
					}else{
						statusRecord = 'dataRecordBot';
						checkBgColorG =0;
					}
					var showDisplayGuestname = "";
					if(ShowNameGuest==""){
						showDisplayGuestname = '<tr clearTr=checkoutReservation class="'+statusRecord+'"   id="btnEditS" >';
					}else{
						showDisplayGuestname = '<tr clearTr=checkoutReservation class="'+statusRecord+'" onclick="if(linkClick) CallEditReservedPageWithLoadElement(id,'+objArray[i].id+')"  id="btnEditS" >';
					}
					var obj = objArray[i];
					//object ot string
					objToStr(obj);
					objArray[i] = obj;
					var re2 = /"/gi;
					var runnumberSub = "";
					if(getCurrentTabData().beforePageCheckout!=undefined&&getCurrentTabData().beforePageCheckout!=""){
						runnumberSub = (numberSet)+"."+(numberSubSet);
						numberSubSet = numberSubSet+1;
					}else{
						runnumberSub = (i+1)+"."+(subRes+1);
					}
					var sendData = JSON.stringify(objArray[i]).replace(re2, "'");
						textRoomCheckOut += showDisplayGuestname+
						'<td colspan="2" class="spanDataCenter">'+
							runnumberSub+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+objArray[i].id+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span class="guestName" >'+ShowNameGuest+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+setDateFormatRes.getFormatedString()+'-'+setFateFormatCheckoutRes.getFormatedString()+' ('+objArray[i].span+')</span>'+
						'</td>'+
						'<td class="spanDataCenter"> '+
							'<span>'+objArray[i].roomTypeName+'('+objArray[i].roomName+')'+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+adult+'('+objArray[i].adult+') - '+child+'('+objArray[i].child+')'+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							StatusResInGroup+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+toCurrencyString(currencyStringToNumber(objArray[i].defaultCherge))+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span><div class="fongwordwarp" >'+DescriptionSubRes+'</div></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<div onmouseover="linkClick=false;" onmouseout="linkClick=true;" >'+
							'<span  onclick="printRoomManagementSinggle('+sendData+')" >'+printPci+'</span>'+
						'<span id="sendMail'+objArray[i].id+'" onclick="sendMail(id)"> '+emailPic+'</span></div>'+
						'</td>'+
						'</tr>';
						textRoomCheckOutPrint += '<tr clearTr=checkoutReservation class="'+statusRecord+'" onclick="if(linkClick&&ShowNameGuest!="") CallEditReservedPageWithLoadElement(id,'+objArray[i].id+')"  id="btnEditS" >'+
						'<td colspan="2" class="spanDataCenter">'+
							runnumberSub+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+objArray[i].id+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span class="guestName" >'+ShowNameGuest+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+setDateFormatRes.getFormatedString()+'-'+setFateFormatCheckoutRes.getFormatedString()+' ('+objArray[i].span+')</span>'+
						'</td>'+
						'<td class="spanDataCenter"> '+
							'<span>'+objArray[i].roomTypeName+'('+objArray[i].roomName+')'+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+adult+'('+objArray[i].adult+') - '+child+'('+objArray[i].child+')'+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							StatusResInGroup+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+toCurrencyString(currencyStringToNumber(objArray[i].defaultCherge))+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span><div class="fongwordwarp" >'+DescriptionSubRes+'</div></span>'+
						'</td>'+
						'</tr>';
				}
			}else{
				res = objArray[i].id;
				var setDateFormat = new Date(objArray[i].date);
				var setFateFormatCheckout = setDateFormat.addDate(parseInt(objArray[i].span));
				getStatusResInGroup = objArray[i].reservationTitle;
				if(getStatusResInGroup=="Reserved Rooms"){
					showStatusResInGroup = statusResv;
				}else if(getStatusResInGroup=="Checked-out Rooms"){
					showStatusResInGroup = statusCheckOut;
				}else if(getStatusResInGroup=="Temp Rooms"){
					showStatusResInGroup = statusTempResv;
				}else if(getStatusResInGroup=="Cancel Reservation"){
					showStatusResInGroup = statusCancelCheckin;
				}else{
					showStatusResInGroup = statusCheckin;
				}
				if(checkBgColor==0){
					statusRecord = 'dataRecordBot';
					checkBgColor = 1;
				}else{
					statusRecord = 'dataRecordBot';
					checkBgColor =0;
				}
				var obj = objArray[i];
				objToStr(obj);//objcet to string
				objArray[i] = obj;
				var re2 = /"/gi;
				var sendData = JSON.stringify(objArray[i]).replace(re2, "'");
				if(getCurrentTabData().beforePageCheckout!=undefined&&getCurrentTabData().beforePageCheckout!=""){
					numberSet = numberSet+1;
					number = numberSet;
				}else{
					number = (i+1);
				}
				if(setDateFormat.getFormatedString()!=undefined){
						textRoomCheckOut += '<tr clearTr=checkoutReservation class="'+statusRecord+'" onclick="if(linkClick){ CallEditReservedPageWithLoadElement(id,'+objArray[i].id+')}" id="btnEditS" >'+
						'<td class="spanDataCenter">'+
							number+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+objArray[i].id+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span class="guestName" >'+objArray[i].name+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+setDateFormat.getFormatedString()+'-'+setFateFormatCheckout.getFormatedString()+' ('+objArray[i].span+')</span>'+
						'</td>'+
						'<td class="spanDataCenter"> '+
							'<span>'+objArray[i].roomTypeName+'('+objArray[i].roomName+')'+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
						'<span>'+adult+'('+objArray[i].adult+') - '+child+'('+objArray[i].child+')'+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+showStatusResInGroup+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+toCurrencyString(currencyStringToNumber(objArray[i].defaultCherge))+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
						'<span><div class="fongwordwarp" >'+Description+'</div></span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<div onmouseover="linkClick=false;" onmouseout="linkClick=true;" >'+
							'<span  onclick="printRoomManagementCheckout('+sendData+')" >'+printPci+'</span>'+
						'<span id="sendMail'+objArray[i].id+'" onclick="sendMail(id)"> '+emailPic+'</span></div>'+
						'</td>'+
					'</tr>';
						textRoomCheckOutPrint += '<tr clearTr=checkoutReservation class="'+statusRecord+'" onclick="if(linkClick){ CallEditReservedPageWithLoadElement(id,'+objArray[i].id+')}" id="btnEditS" >'+
						'<td class="spanDataCenter">'+
							number+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span></span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
							'<span>'+objArray[i].id+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span class="guestName" >'+objArray[i].name+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+setDateFormat.getFormatedString()+'-'+setFateFormatCheckout.getFormatedString()+' ('+objArray[i].span+')</span>'+
						'</td>'+
						'<td class="spanDataCenter"> '+
							'<span>'+objArray[i].roomTypeName+'('+objArray[i].roomName+')'+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">' +
						'<span>'+adult+'('+objArray[i].adult+') - '+child+'('+objArray[i].child+')'+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+showStatusResInGroup+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
							'<span>'+toCurrencyString(currencyStringToNumber(objArray[i].defaultCherge))+'</span>'+
						'</td>'+
						'<td class="spanDataCenter">'+
						'<span><div class="fongwordwarp" >'+Description+'</div></span>'+
						'</td>'+
					'</tr>';
				}
			}
		}
		if(textRoomCheckOut==""){
			var textDataEmpty = '<tr clearTr="checkoutReservation" >'+
			'<td colspan="100%" style="text-align:center;" >'+
			dataEmpty+
			'</td>'+
			'</tr>';
			textRoomCheckOut = textDataEmpty;
		}
		$("#CheckOutListRoomManageMent_Id_Tr").replaceWith("<tr id=CheckOutListRoomManageMent_Id_Tr ></tr>"+textRoomCheckOut);
		textRoomCheckOut = "";
		textSubRes = "";
		textPrint = textRoomCheckOutPrint;
	}
	dateRoomManageMent({checkin:"calendar_btw_checkinCheckout",atrcheckin:"dateofBtwCheckinCheckout"},{checkout:"calendar_btw_checkoutCheckout",atrcheckout:"dateofBtwCheckoutCheckout"});
	$(".ui-datepicker-trigger").css("margin-top","2px");
	closeWaitingDialog();
	showDataResRoomManageMentSetPageCheckout(data,tab.lineCheckout);
}

function showDataResRoomManageMentSetPageCheckout(data,output){
	$("[clearTr*=checkoutReservationPage]").remove();
	if(data!="textSearch"){
		objArray = JSON.parse(data);
		objArray = objArray[1];
		var textRoomCheckOutSetpage = "";
		for(var i =0;i<objArray.length;i++){
			var textSubRes = "";
			if(objArray[i].groupId!="0"){
				var statusRecord = "";
				for(var subRes = 0;subRes<objArray[i].subList.length;subRes++){
					textSubRes += '<tr clearTr=checkoutReservationPage  ><td></td></tr>';
				}
				textRoomCheckOutSetpage += '<tr clearTr=checkoutReservationPage class="trcheckout"><td></td></tr>'+textSubRes;
			}else{
				textRoomCheckOutSetpage += '<tr clearTr=checkoutReservationPage ><td></td></tr>';
			}
		}
		$("[name = CheckOutListRoomManageMent_Id_Tr2]").replaceWith("<tr name=CheckOutListRoomManageMent_Id_Tr2></tr>"+textRoomCheckOutSetpage);
		textRoomCheckOutSetpage = "";
		textSubRes = "";
		showPager(output);
	}
}

function showDataResRoomManageMentSetCountCheckout(data,output){
	var subCount = 0;
	var recCount = 0;
	var objArray = new Array();
	if((data=="textSearch"||data=="G"||data=="S"||data=="A"||data=="reservationType_A"||data=="Checked-out Rooms"||data=="Checked-in Rooms")&&data!="dateSearch"){
		objArray = oldObjArrayCheckout;
		objArrayCheck = objArray[0];
		objArray = objArray[1];
	}else{
		objArray = JSON.parse(data);
		oldObjArrayCheckout = objArray;
		objArrayCheck = objArray[0];
		objArray = objArray[1];
	}
	setRowObjArrayCheckout = objArray;
	sortIdRoommanagement(objArray);
	sortIdRoommanagement(objArrayCheck);
	for(var i =0;i<objArray.length;i++){
		if(objArray[i].groupId!="0"){
			if(objArray[i].subList!=undefined){
				if(objArrayCheck[objArrayCheck.length-1].groupId==objArray[i].groupId){
					recCount = (i+1);
					subCount = objArrayCheck[objArrayCheck.length-1].subList.length+1;
					break;
				}
			}else{
				if(objArrayCheck[objArrayCheck.length-1].groupId==objArray[i].groupId){
					recCount = (i+1);
					break;
				}
			}
		}else{
			if(objArrayCheck[objArrayCheck.length-1].id==objArray[i].id){
				recCount = (i+1);
				break;
			}
		}
	}
	var tab = getCurrentTabData();
	tab.beforePageCheckout = (recCount);
	tab.beforeSubPageCheckout = subCount;
	simpleservice(tab.linkSet,null,showDataResRoomManageMent,data);
}

function typeReservationCheckoutFunction(dataOld,offfset,pagePointer,dateCheckin,dateCheckout,data,searchName){
	
	var tab = getCurrentTabData();
	if(dataOld=="G"){
		tab.typeReservationCheckout = dataOld;
		if(pagePointer>1){
			var link = "/reservationService?func=getReservationAllCheckoutOnlyGroup&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			var linkSet = "/reservationService?func=getReservationAllCheckoutOnlyGroup&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			tab.linkSet = linkSet;
			simpleservice(link,null,showDataResRoomManageMentSetCountCheckout,tab.lineCheckout);
		}else{
			var link = "/reservationService?func=getReservationAllCheckoutOnlyGroup&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			simpleservice(link,null,showDataResRoomManageMent,data);
		}
	}else if(dataOld=="S"){
		tab.typeReservationCheckout = dataOld;
		if(pagePointer>1){
			var link = "/reservationService?func=getReservationAllCheckoutOnlySingle&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			var linkSet = "/reservationService?func=getReservationAllCheckoutOnlySingle&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			tab.linkSet = linkSet;
			simpleservice(link,null,showDataResRoomManageMentSetCountCheckout,tab.lineCheckout);
		}else{
			var link = "/reservationService?func=getReservationAllCheckoutOnlySingle&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			simpleservice(link,null,showDataResRoomManageMent,data);
		}
	}else if(dataOld=="A"){
		tab.typeReservationCheckout = dataOld;
		if(pagePointer>1){
			var link = "/reservationService?func=getReservationAllCheckoutOnly&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+(pagePointer-1)+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			var linkSet = "/reservationService?func=getReservationAllCheckoutOnly&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			tab.linkSet = linkSet;
			simpleservice(link,null,showDataResRoomManageMentSetCountCheckout,tab.lineCheckout);
		}else{
			tab.beforePageCheckout = ""; 
			tab.beforeSubPageCheckout = "";
			var link = "/reservationService?func=getReservationAllCheckoutOnly&offset="
				+offfset+"&line="+tab.lineCheckout+"&pagePointer="+pagePointer+"&dateCheckin="+dateCheckin+"&dateCheckout="+dateCheckout
				+"&SearchAll_checkoutPage="+searchName;
			simpleservice(link,null,showDataResRoomManageMent,data);
		}
	}
}
//////////////End Check Out Page ////////////////